package com.gongzonqiang.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.gongzonqiang.Interceptor.AdminInterceptor;
 
/**
 * Created by CrazyIter on 2017/3/27.
 */
//@EnableWebMvc
//@Configuration
@SpringBootConfiguration
public class WebConfig  extends WebMvcConfigurerAdapter {

	@Autowired
	private AdminInterceptor  adminInterceptor;
	
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		InterceptorRegistration addInterceptor = registry.addInterceptor(adminInterceptor);
		 // 排除配置
		addInterceptor.excludePathPatterns("/admin/exitAdmin");
		addInterceptor.excludePathPatterns("/admin/loginAdmin");
		// 添加一个拦截器，连接以/admin为前缀的 url路径
		addInterceptor.addPathPatterns("/admin/**");
	}
//    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//        MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
//        ObjectMapper objectMapper = new ObjectMapper();
//        /**
//         * 序列换成json时,将所有的long变成string
//         * 因为js中得数字类型不能包含所有的java long值
//         */
//        SimpleModule simpleModule = new SimpleModule();
//        simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
//        simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
//        objectMapper.registerModule(simpleModule);
//        jackson2HttpMessageConverter.setObjectMapper(objectMapper);
//        converters.add(jackson2HttpMessageConverter);
//    }
	
	
}
